<template>
    <div class="common-layout">
      <el-container>
        <el-header>
          <el-menu
            :default-active="activeIndex"
            class="el-menu-demo"
            mode="horizontal"
            :ellipsis="false"
            @select="handleSelect">
            <el-menu-item index="0">
              <img
                style="width: 100px"
                src="../src/assets/images/4.png"
                width="120px"
                height="50px"
                alt="Element logo"/>
            </el-menu-item>
            <div class="flex-grow" />
            <el-menu-item index="1">用户名</el-menu-item>
            <el-sub-menu index="2">
              <template #title>个人中心</template>
              <el-menu-item index="2-1">账号设置</el-menu-item>
              <el-menu-item index="2-2">个人信息</el-menu-item>
              <el-menu-item index="2-3">权限列表</el-menu-item>
              <el-sub-menu index="2-4">
                <template #title>账号状态</template>
                <el-menu-item index="2-4-1" @click="zhu">注册账号</el-menu-item>
                <el-menu-item index="2-4-2">更换账号</el-menu-item>
                <el-menu-item index="2-4-3">注销账号</el-menu-item>
              </el-sub-menu>
            </el-sub-menu>
          </el-menu>
        </el-header>
        <el-container>
          <el-aside width="200px">
            <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
              <el-radio-button :value="false">展开</el-radio-button>
              <el-radio-button :value="true">折叠</el-radio-button>
            </el-radio-group>
            <el-menu
              default-active="2"
              class="el-menu-vertical-demo"
              :collapse="isCollapse"
              @open="handleOpen"
              @close="handleClose">
              <el-sub-menu index="1">
                <template #title>
                  <el-icon><location /></el-icon>
                  <span>角色</span>
                </template>
                <el-menu-item-group>
                  <template #title><span>权限</span></template>
                  <el-menu-item index="1-1" @click="quan">权限分配</el-menu-item>
                  <el-menu-item index="1-2">权限修改</el-menu-item>
                  <el-menu-item index="1-3" @click="task">分配人员</el-menu-item>
                </el-menu-item-group>
                <el-menu-item-group title="任务">
                  <el-menu-item index="1-4">任务进度</el-menu-item>
                  <el-menu-item index="1-5" @click="add">创建项目</el-menu-item>
                  <el-menu-item index="1-6" @click="load">上传文件</el-menu-item>
                </el-menu-item-group>
              </el-sub-menu>
              <el-menu-item index="2">
                <el-icon><icon-menu /></el-icon>
                <template #title>任务需求</template>
<!--                <el-menu-item index="2-1" @click="shang">上传文件</el-menu-item>-->
              </el-menu-item>
            </el-menu>
          </el-aside>
          <el-main>
            <router-view />
          </el-main>
        </el-container>
      </el-container>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { ElMenu, ElMenuItem } from 'element-plus';
import router from "./router";
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'
const isCollapse = ref(true);
const zhu = () => {
    // 使用router.push来导航到登录页面
    router.push({ path: '/login' });
};
// 定义导航到权限分配页面的方法
const quan = () => {
    // 使用router.push来导航到权限分配页面
    router.push({ path: '/role' });
};

// 定义导航到创建项目分配页面的方法
const add = () => {
  // 使用router.push来导航到创建项目分配页面
  router.push({ path: '/addpro' });
}

// 定义导航到任务分配页面的方法
const task = () => {
  // 使用router.push来导航到任务分配页面
  router.push({ path: '/task' });
}
// 定义导航到上传文件页面的方法
const load = () => {
  // 使用router.push来导航到任务分配页面
  router.push({ path: '/load' });
}
const handleOpen = (key: string, keyPath: string[]) => {
    console.log(key, keyPath);
}

const handleClose = (key: string, keyPath: string[]) => {
    console.log(key, keyPath);
}

const activeIndex = ref('1');
const handleSelect = (key: string, keyPath: string[]) => {
    console.log(key, keyPath);
}
</script>

<style>
.flex-grow {
    flex-grow: 1;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>